import 'package:flutter/material.dart';
import 'package:flutter_application_2/widgets/common_image.dart';

class SearchBar extends StatefulWidget {
  final bool showLoaction; //展示位置按钮
  final Function goBackCallback; //回退按钮函数
  final String inputValue; // 搜索框输入值
  final String defaultInputValue; // 搜索框默认值
  final Function onCancel; //取消按钮
  final bool showMap; //展示地图按钮
  final Function onSearch; //用户点击搜索框触发
  final ValueChanged<String> onSearchSubmit;

  const SearchBar(
      {Key key,
      this.showLoaction,
      this.goBackCallback,
      this.inputValue,
      this.defaultInputValue,
      this.onCancel,
      this.showMap,
      this.onSearch,
      this.onSearchSubmit})
      : super(key: key); // 用户输入搜索词后，点击键盘的搜索键触发
  @override
  _SearchBarState createState() => _SearchBarState();
}

class _SearchBarState extends State<SearchBar> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          if (widget.showLoaction != null || true)
            Padding(
              padding: EdgeInsets.only(right: 10.0),
              child: GestureDetector(
                onTap: () {},
                child: Row(
                  children: [
                    Icon(
                      Icons.room,
                      color: Colors.green,
                    ),
                    Text(
                      '北京',
                      style: TextStyle(color: Colors.black, fontSize: 14.0),
                    )
                  ],
                ),
              ),
            ),
          if (widget.goBackCallback != null || true)
            Padding(
              padding: EdgeInsets.only(right: 10.0),
              child: GestureDetector(
                onTap: widget.goBackCallback,
                child: Icon(
                  Icons.chevron_left,
                  color: Colors.black,
                ),
              ),
            ),
          Expanded(
              child: Container(
            height: 34.0,
            // padding: EdgeInsets.only(left: -10.0),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(17.0),
              color: Colors.grey[200],
            ),
            child: TextField(
              style: TextStyle(fontSize: 14.0),
              decoration: InputDecoration(
                  contentPadding: EdgeInsets.only(top: 0.1, left: -10.0),
                  hintText: '请输入搜索词',
                  border: InputBorder.none,
                  suffixIcon: Icon(
                    Icons.clear,
                    size: 16.0,
                  ),
                  icon: Padding(
                    padding: EdgeInsets.only(top: 2.0, left: 8.0),
                    child: Icon(
                      Icons.search,
                      size: 16.0,
                    ),
                  )),
            ),
          )),
          if (widget.onCancel != null || true)
            Padding(
              padding: EdgeInsets.only(left: 10.0),
              child: GestureDetector(
                onTap: widget.onCancel,
                child: Text(
                  '取消',
                  style: TextStyle(color: Colors.black, fontSize: 14.0),
                ),
              ),
            ),
          if (widget.showMap != null || true)
            Padding(
              padding: EdgeInsets.only(left: 10.0),
              child: GestureDetector(
                onTap: () {},
                child: CommonImage('static/images/widget_search_bar_map.png'),
              ),
            )
        ],
      ),
    );
  }
}
